package net.y2t72.microblog.web;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import net.y2t72.microblog.bean.Member;
import net.y2t72.microblog.biz.MemberBiz;
import net.y2t72.microblog.biz.impl.MemberBizImpl;

public class UpdateUser extends HttpServlet {

	/**
	 * 版本号
	 */
	private static final long serialVersionUID = 6974212854575159434L;

	/**
	 * The doGet method of the servlet. <br>
	 *
	 * This method is called when a form has its tag value method equals to get.
	 * 
	 * @param request the request send by the client to the server
	 * @param response the response send by the server to the client
	 * @throws ServletException if an error occurred
	 * @throws IOException if an error occurred
	 */
	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {

		response.setContentType("text/html");
		PrintWriter out = response.getWriter();
		String statue=request.getParameter("statue");
		Member member = new Member();
		 member.setId(1);   //先设在这  以后该
		MemberBiz memberBiz = new MemberBizImpl();
		if (statue.equals("jiben")) {
			 String name=request.getParameter("name");
			    String gender=request.getParameter("gender");
			    String address1=request.getParameter("address1");
			    String address2=request.getParameter("address2");
			    String display=request.getParameter("display");
			    member.setNickname(name);
			    member.setGender(gender);
			    member.setDistrict(address1+" "+address2);
			    member.setIntroduction(display);
		}else if (statue.equals("mima")) {
			String Opass=request.getParameter("Opass");
			member = memberBiz.SeachMember(1);  //获取id 进行查询
			if (!(member.getPassword().equals(Opass))) {
				out.print(0);
				return;
			}
			String Npass = request.getParameter("Npass");
			member.setPassword(Npass);
		}else{
			
		}
	    int count=memberBiz.updateMember(member, statue);
	    out.print(count);
		out.flush();
		out.close();
	}

	/**
	 * The doPost method of the servlet. <br>
	 *
	 * This method is called when a form has its tag value method equals to post.
	 * 
	 * @param request the request send by the client to the server
	 * @param response the response send by the server to the client
	 * @throws ServletException if an error occurred
	 * @throws IOException if an error occurred
	 */
	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
      doGet(request, response);
	}

}
